package com.ruoyi.web.controller.production.pesticide;

import java.util.List;

import com.ruoyi.common.annotation.PropertyInject;
import com.ruoyi.common.enums.InjectType;
import com.ruoyi.production.domain.pesticide.PesticidePurchaseApply;
import com.ruoyi.production.service.pesticide.IPesticidePurchaseApplyService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 农药购买申请Controller
 *
 * @author testlove
 * @date 2021-07-11
 */
@RestController
@RequestMapping("/system/pesticideApply")
@Api("农药购买申请")
public class PesticidePurchaseApplyController extends BaseController
{
    @Autowired
    private IPesticidePurchaseApplyService pesticidePurchaseApplyService;

    /**
     * 查询农药购买申请列表
     */
    @PreAuthorize("@ss.hasPermi('system:pesticideApply:list')")
    @GetMapping("/list")
    @ApiOperation("查询农药购买申请列表")
    public TableDataInfo list(PesticidePurchaseApply pesticidePurchaseApply)
    {
        startPage();
        List<PesticidePurchaseApply> list = pesticidePurchaseApplyService.selectPesticidePurchaseApplyList(pesticidePurchaseApply);
        return getDataTable(list);
    }

    /**
     * 导出农药购买申请列表
     */
    @PreAuthorize("@ss.hasPermi('system:pesticideApply:export')")
    @Log(title = "农药购买申请", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(PesticidePurchaseApply pesticidePurchaseApply)
    {
        List<PesticidePurchaseApply> list = pesticidePurchaseApplyService.selectPesticidePurchaseApplyList(pesticidePurchaseApply);
        ExcelUtil<PesticidePurchaseApply> util = new ExcelUtil<PesticidePurchaseApply>(PesticidePurchaseApply.class);
        return util.exportExcel(list, "农药购买申请数据");
    }

    /**
     * 获取农药购买申请详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:pesticideApply:query')")
    @GetMapping(value = "/{pesticidePurchaseApplyId}")
    public AjaxResult getInfo(@PathVariable("pesticidePurchaseApplyId") Long pesticidePurchaseApplyId)
    {
        return AjaxResult.success(pesticidePurchaseApplyService.selectPesticidePurchaseApplyById(pesticidePurchaseApplyId));
    }

    /**
     * 新增农药购买申请
     */
    @PreAuthorize("@ss.hasPermi('system:pesticideApply:add')")
    @Log(title = "农药购买申请", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation("新增农药购买申请")
    @PropertyInject(type = InjectType.Insert)
    public AjaxResult add(@RequestBody PesticidePurchaseApply pesticidePurchaseApply)
    {
        return toAjax(pesticidePurchaseApplyService.insertPesticidePurchaseApply(pesticidePurchaseApply));
    }

    /**
     * 修改农药购买申请
     */
    @PreAuthorize("@ss.hasAnyPermi('system:pesticideApply:edit,system:pesticideApply:permit')")
    @Log(title = "农药购买申请", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation("修改农药购买申请")
    public AjaxResult edit(@RequestBody PesticidePurchaseApply pesticidePurchaseApply)
    {
        return toAjax(pesticidePurchaseApplyService.updatePesticidePurchaseApply(pesticidePurchaseApply));
    }

    /**
     * 删除农药购买申请
     */
    @PreAuthorize("@ss.hasPermi('system:pesticideApply:remove')")
    @Log(title = "农药购买申请", businessType = BusinessType.DELETE)
	@DeleteMapping("/{pesticidePurchaseApplyIds}")
    public AjaxResult remove(@PathVariable Long[] pesticidePurchaseApplyIds)
    {
        return toAjax(pesticidePurchaseApplyService.deletePesticidePurchaseApplyByIds(pesticidePurchaseApplyIds));
    }
}
